package com.white.hot.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.white.hot.dto.Goods;
import com.white.hot.dto.resp.BaseResp;
import com.white.hot.service.GoodsService;

import commom.Page;

@Controller
@RequestMapping("/goods")
public class GoodsController extends BaseController
{
	@Resource
	private GoodsService goodsService;
	
	@RequestMapping("/getList")
	@ResponseBody
	private Object getList(HttpServletRequest request, HttpServletResponse resp)
	{
		BaseResp br = new BaseResp();
		Page page = new Page();
		Map<String,String[]> param = request.getParameterMap();
		String p[] = param.get("page");
		String c[] = param.get("count");
		if(p != null && p.length > 0 & c != null && c.length > 0)
		{
			page.count = Integer.parseInt(c[0]);
			page.offset = (Integer.parseInt(p[0]) - 1) * page.count;
		}
		List<Goods> list = goodsService.getList(page);
		br.rows = list;
		try
		{
			Thread.sleep(1200);
		} catch (InterruptedException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return buildSuccessResp(br);
	}
	
	@RequestMapping("/getp1")
	@ResponseBody
	private Object getp1(HttpServletRequest request, HttpServletResponse resp)
	{
		BaseResp br = new BaseResp();
		
		return buildSuccessResp(br);
	}
	
	@RequestMapping("/getp1/getp2")
	@ResponseBody
	private Object getp2(HttpServletRequest request, HttpServletResponse resp)
	{
		BaseResp br = new BaseResp();
		System.out.println(request.getHeader("User-Agent"));		
		return buildSuccessResp(br);
	}
	
	@RequestMapping("/getp1/getp2/getp3")
	@ResponseBody
	private Object getp3(HttpServletRequest request, HttpServletResponse resp)
	{
		BaseResp br = new BaseResp();		
		return buildSuccessResp(br);
	}
	
	@RequestMapping("/postp1/postp2")
	@ResponseBody
	private Object postp2(HttpServletRequest request, HttpServletResponse resp)
	{
		BaseResp br = new BaseResp();
		System.out.println(request.getParameter("haha"));
		return buildSuccessResp(br);
	}
	
	@RequestMapping("/postp1/postp2/postp3")
	@ResponseBody
	private Object postp3(HttpServletRequest request, HttpServletResponse resp)
	{
		BaseResp br = new BaseResp();
		System.out.println(request.getParameter("haha"));
		return buildSuccessResp(br);
	}
}
